// pages/editinfo/editinfo.js
const db = wx.cloud.database()
const user = db.collection('user')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    username:"",
    userstuid:"",
    userphone:"",
    openid:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this
    var tempuserinfo = {}
    var userinfo = {}
    user.get().then(res => {
      tempuserinfo = res.data[0]
      console.log(tempuserinfo)
      console.log(tempuserinfo.username)
      if (tempuserinfo.extraUserInfo.username == null)
        userinfo.username = "未填写"
      else userinfo.username = tempuserinfo.extraUserInfo.username

      if (tempuserinfo.extraUserInfo.userphone == null)
        userinfo.userphone = "未填写"
      else userinfo.userphone = tempuserinfo.extraUserInfo.userphone

      if (tempuserinfo.extraUserInfo.userstuid == null)
        userinfo.userstuid = "未填写"
      else userinfo.userstuid = tempuserinfo.extraUserInfo.userstuid

      _this.setData({
        username: userinfo.username,
        userstuid: userinfo.userstuid,
        userphone: userinfo.userphone,
        openid: res.data[0]._openid
      })
    })
  },

  onClickName: function (e) {
    var modifyitem = 'username'
    var itemcname = '姓名'
    wx.navigateTo({
      url: '../modifysingleinfo/modifysingleinfo?modifyitem=' + modifyitem + '&itemcname=' + itemcname
    })
  },

  onClickStuid: function (e) {
    var modifyitem = 'userstuid'
    var itemcname = '学号'
    wx.navigateTo({
      url: '../modifysingleinfo/modifysingleinfo?modifyitem=' + modifyitem + '&itemcname=' + itemcname
    })
  },

  onClickPhone: function (e) {
    var modifyitem = 'userphone'
    var itemcname = '手机'
    wx.navigateTo({
      url: '../modifysingleinfo/modifysingleinfo?modifyitem=' + modifyitem + '&itemcname=' + itemcname
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})